Skip to content

fix: force UTF-8 output encoding for PowerShell on Windows - #49012

Closed
ysmla wants to merge 1 commit into
anomalyco:devfrom
ysmla:fix/windows-powershell-utf8
Closed

ysmla wants to merge 1 commit into
anomalyco:devfrom
ysmla:fix/windows-powershell-utf8

Conversation

@ysmla

@ysmla ysmla commented Sep 14, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #30205

Related: #30055, #23636

Type of change

  • Bug fix

What does this PR do?

解决Windows下,opencode中模型使用powershell输出中文时会出现乱码的问腿

How did you verify your code works?

在中文 Windows 11 + PowerShell 5.1 环境下,用与工具相同的方式启动 PowerShell(管道输出 stdout),会得到 GBK 编码字节(b2e2 cad4 ...),证实了乱码的原因是编码不匹配,修复后,用重新构建的二进制做端到端测试,让模型执行 echo 测试中文:你好世界——打补丁前输出乱码,打补丁后能正确显示中文。
修复前后对比如下:
origin
fixed

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title Fix/windows powershell utf8 doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found

This PR appears to be directly related to previous Windows PowerShell UTF-8 encoding fixes:

  1. fix(core): force UTF-8 for Windows shells #36608 - fix(core): force UTF-8 for Windows shells
    fix(core): force UTF-8 for Windows shells #36608

  2. fix: set default UTF-8 encoding for spawned subprocess on Windows #31658 - fix: set default UTF-8 encoding for spawned subprocess on Windows
    fix: set default UTF-8 encoding for spawned subprocess on Windows #31658

Why they're related: All three PRs address the same core issue—fixing UTF-8 encoding problems for PowerShell output on Windows. PR #49012 mentions it's related to issues #30205 and #30055, and appears to implement a similar fix by injecting [Console]::OutputEncoding = UTF-8 into PowerShell commands.

You should verify whether these previous PRs already resolved the issue or if this is addressing a gap they missed.

@ysmla ysmla changed the title Fix/windows powershell utf8 fix/windows powershell utf8 Sep 14, 2026
Windows PowerShell 5.1 encodes its stdout with the legacy OEM code page
(e.g. CP936 on zh-CN systems) when output is redirected, while opencode
decodes process output as UTF-8, producing mojibake for any non-ASCII
shell output.

Prepend a [Console]::OutputEncoding/$OutputEncoding UTF-8 preamble to
PowerShell commands spawned by the shell tool and bang commands on
Windows. Permission scanning and command titles still use the original
command text since the preamble is injected at spawn time.

Corresponds to upstream discussion in anomalyco#23636.
@ysmla
ysmla force-pushed the fix/windows-powershell-utf8 branch from 8aef152 to 042190d Compare September 14, 2026 16:49
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 14, 2026
@github-actions github-actions Bot closed this Sep 14, 2026
@ysmla ysmla changed the title fix/windows powershell utf8 fix: force UTF-8 output encoding for PowerShell on Windows Sep 15, 2026
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

在 Window 环境下 AI 使用 PowerShell 修改文件添加中文内容会有乱码出现

1 participant